package com.example.demo.algorithm.sort.bubble_sort;

/**
 * @author: htc
 * @date: Created in 11:01 2019/2/21.
 */
public class Demo {

    public static void bubbleSort() {
        int[] arr = {6, 3, 8, 2, 9, 1};
        //外层循环控制排序趟数
        for (int i = 0; i < arr.length - 1; i++) {
            //内层循环控制每一趟排序多少次
            for (int j = 0; j < arr.length - i - 1; j++) {
                if (arr[j] > arr[j + 1]) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
        for (int num : arr) {
            System.out.print(num + " ");
        }
    }

    public static void main(String[] args) {
        bubbleSort();
    }
}
